package pandora.bo.JMPG;

import java.util.List;

import pandora.data.ICommentDAO;
import pandora.data.ICustomerDAO;
import pandora.data.IRatingDAO;
import pandora.data.IStoreDAO;
import pandora.data.mysql.JDBCCommentDAO;
import pandora.data.mysql.JDBCCustomerDAO;
import pandora.data.mysql.JDBCRatingDAO;
import pandora.data.mysql.JDBCStoreDAO;
import pandora.dto.CommentDTO;
import pandora.dto.CustomerDTO;
import pandora.dto.RatingDTO;
import pandora.dto.StoreDTO;

public class StoreModule implements IStoreModule {

	@Override
	public List<StoreDTO> getListStore() {
		IStoreDAO storeDAO = new JDBCStoreDAO();
		
		List<StoreDTO> stores;
		
		stores = storeDAO.getAllStores();
		
		return stores;
	}

	@Override
	public StoreDTO getStoreDetail(String nif) {
		IStoreDAO storeDAO = new JDBCStoreDAO();
		
		StoreDTO detailStore;
		
		detailStore = storeDAO.getStoreByNIF(nif);
		
		return detailStore;
	}

	@Override
	public List<CommentDTO> getComments(String nif) {
		ICommentDAO commentDAO = new JDBCCommentDAO();
		
		List<CommentDTO> comentarios;
		
		comentarios = commentDAO.getCommentsByStore(nif);
		
		return comentarios;
	}

	@Override
	public Float getAverageRatings(String nif) {
		IRatingDAO ratingDAO = new JDBCRatingDAO();
		
		Float media;
		
		media = ratingDAO.getAverageRating(nif);
		
		return media;
	}

	@Override
	public Float getRatingsByType(String nif, String type) {
		IRatingDAO ratingDAO = new JDBCRatingDAO();
		IStoreDAO storeDAO = new JDBCStoreDAO();
		
		StoreDTO store = storeDAO.getStoreByNIF(nif);
		
		return ratingDAO.getAverageRatingByType(store, type);

	}

	@Override
	public void saveComment(CommentDTO comentario) {
		ICommentDAO commentDAO = new JDBCCommentDAO();
		
		commentDAO.saveComment(comentario);
		
	}

	@Override
	public CustomerDTO getUserByUserName(String user) {
		ICustomerDAO customerDAO = new JDBCCustomerDAO();
		
		CustomerDTO usr = customerDAO.selectCustomerByAccount(user);
				
		return usr;
	}

	@Override
	public RatingDTO getRating(String nif, String type, String usr) {
		IRatingDAO ratingDAO = new JDBCRatingDAO();
			
		
		return ratingDAO.getRatingByUser(nif,type,usr);

	}
	
	public void saveRating(List<RatingDTO> r) {
		IRatingDAO ratingDAO = new JDBCRatingDAO();
		
		ratingDAO.saveRatings(r);
	}
	
	
}
